package com.cdn.website.service.impl;

import com.cdn.website.service.NginxService;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class NginxServiceImpl implements NginxService {

    /**
     * 执行 Nginx 热重载，应用新配置
     *
     * @return 是否重载成功
     */
    public boolean reloadNginx() {
        try {
            Process process = Runtime.getRuntime().exec("nginx -s reload");
            int exitCode = process.waitFor();
            return exitCode == 0;  // 0 表示成功
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
            return false;
        }
    }

}
